/**
 * Created by zxh on 14-7-11.
 */

ms.UIZhenDuan = ms.UILayer.extend({
    _stepIndex: null,
    _taolunIndex: null,
    ctor: function() {
        this._super();
        this._ccsFileName = "zhenduan4.json";
        this._stepIndex = 0;
        this._taolunIndex = 0;
    },

    onEnter: function() {
        this._super();
        this._continueButton.setVisible(false);
        this._taolunButton.setVisible(false);
        this._okButton.setVisible(false);

        for (var i = 1; i <=4 ; i++) {
            var checkBox  = this["_checkBox" + i];
            checkBox.addEventListenerCheckBox(this.onCheckBoxChanged, this);
        }

        //创建柱状图表
        var barChart = ms.createLayer(ms.UIBarChart);
        //设置数据
        barChart.setData(1, 60); //A
        barChart.setData(2, 20); //B
        barChart.setData(3, 40); //C
        barChart.setData(4, 10); //D

        barChart.x = this.width * 1.23;
        barChart.y = this.height * 0.463;
        barChart.setVisible(false);
        this.rootNode.addNode(barChart);
        this._barChart = barChart;
    },

    onCheckBoxChanged: function() {
        for (var i = 1; i <=4 ; i++) {
            var checkBox = this["_checkBox" + i];
            if (checkBox.selected) {
                this._okButton.setVisible(true);
                return;
            }
        }
        this._okButton.setVisible(false);
    },

    onOkButtonTouchEnded: function() {

        if (!this._barChart.isVisible()) {
            this._barChart.setVisible(true);
            var point = this._barChart.getPosition();
            var size = cc.director.getWinSize();
            point.x = size.width * 0.4;
            var move = cc.MoveTo.create(0.3, point);
            this._barChart.runAction(move);
            this._okButton.setVisible(false);
        }
        this._continueButton.setVisible(true);
        this._taolunButton.setVisible(true);
    },

    onTaolunButtonTouchEnded: function() {
        var self = this;
        this._imageText.setVisible(true);
        //this._imageText.setLocalZOrder(10);
        ccs.actionManager.playActionByName(this._ccsFileName, "a1");
    },

    onContinueButtonTouchEnded: function() {
        if (this._stepIndex === 0) {
            this._stepIndex++;
            this._panelLabel1.setVisible(false);
            this._panelLabel2.setVisible(true);

            this._barChart.setVisible(false);
            this._barChart.x = this.width * 1.23;

            for (var i = 1; i <=4 ; i++) {
                var checkBox = this["_checkBox" + i];
                checkBox.selected = false;
            }
        } else {
            cc.director.runScene(ms.createScene(ms.UIBinFang));
        }

    },

    onCloseButtonTouchEnded: function(sender) {
        this._imageText.x = this.width * 1.23;
        this._imageText.setVisible(false);
    }


});